#include <boost/asio.hpp>
#include <iostream>
#include <boost/array.hpp>
#include <string>

int main() {
    try {
        boost::asio::io_context io_context;
        boost::asio::ip::udp::socket socket(io_context, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 12345));

        for (;;) {
            boost::array<char, 1024> recv_buf;
            boost::asio::ip::udp::endpoint sender_endpoint;
            size_t len = socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint);

            std::cout << "Received: " << std::string(recv_buf.data(), len) << " from " << sender_endpoint << std::endl;

            // Echo back the message to the sender
            socket.send_to(boost::asio::buffer(recv_buf, len), sender_endpoint);
        }
    } catch (std::exception& e) {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}